﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using JKF.DataModule.SqlServerDAL;
using JKF.Entities.Model;

namespace JKF.BusinessLayer.BLL
{
   public partial  class bllPRODUCT
    {
       /// <summary>  
        /// 获取产品列表
        /// </summary>
        /// <param name="TYPE">分类</param>
        /// <param name="NAME">产品名称</param>
        /// <param name="MODEL">型号/规格</param>
        /// <param name="pageCurrent">当前页码</param>
        /// <param name="pageSize">一页显示多少</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="rowCount">总记录数</param>
        /// <returns>返回DataTable结果集</returns>
       public  DataTable GetProductsBLL(SYS_USERinfo userinfo,string TYPE, string NAME, string MODEL, int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
       {
           return dalPRODUCT.GetProductsDAL(userinfo,TYPE, NAME, MODEL, pageCurrent, pageSize, ref pageCount, ref rowCount);
       }
       /// <summary>
       /// 执行Sql语句（包括插入Insert和更新Update）
       /// </summary>
       /// <param name="sql"></param>
       /// <returns></returns>
       public  bool ProductSQLBLL(string sql)
       {
           return dalPRODUCT.ProductSQLDAL(sql);
       }
        /// <summary>
        /// 事务删除产品 
        /// </summary>
        /// <param name="shop_code">产品 ID</param>
        /// <returns></returns>
       public  string TransactionSQLDeleteBLL(Guid user_key,Guid product_key)
       {
           return dalPRODUCT.TransactionSQLDeleteDAL(user_key,product_key);
       }
       /// <summary>
        /// 判断产品名称是否存在
        /// </summary>
        /// <param name="product_sort_name"></param>
        /// <returns></returns>
       public  bool ExistsProductNameBLL(string product_name)
       {
           return dalPRODUCT.ExistsProductNameDAL(product_name);
       }

       /// <summary>
        /// 构建产品分类与产品的树结构数据
        /// </summary> 
        /// <returns>返回List结果集</returns>
       public List<PRODUCT_SORT_TREE> GetProduct_SortTreeBLL()
       {
           return DataTableToTreeList(dalPRODUCT.GetProduct_SortTreeDAL());
       }
       /// <summary>
       /// 将返回的DataTable数据转成List形式
       /// </summary>
       /// <param name="dt"></param>
       /// <returns></returns>
       public List<PRODUCT_SORT_TREE> DataTableToTreeList(DataTable dt)
       {
           List<PRODUCT_SORT_TREE> modelList = new List<PRODUCT_SORT_TREE>();
           int rowsCount = dt.Rows.Count;
           if (rowsCount > 0)
           {
               PRODUCT_SORT_TREE model;
               for (int n = 0; n < rowsCount; n++)
               {
                   model = new PRODUCT_SORT_TREE();
                   if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                   {
                       model.ID = dt.Rows[n]["ID"].ToString();
                   }
                   if (dt.Rows[n]["NAME"] != null && dt.Rows[n]["NAME"].ToString() != "")
                   {
                       model.NAME = dt.Rows[n]["NAME"].ToString();
                   } 
                   if (dt.Rows[n]["PID"] != null && dt.Rows[n]["PID"].ToString() != "")
                   {
                       model.PID = dt.Rows[n]["PID"].ToString();
                   }
                   modelList.Add(model);
               }
           }
           return modelList;
       }

       /// <summary>
       /// 自定义模块表与操作表类，以组装树形结构
       /// </summary>
       public class PRODUCT_SORT_TREE
       {
           /// <summary>
           /// 主键
           /// </summary>
           public string ID { get; set; }
           /// <summary>
           ///  名称
           /// </summary>
           public string NAME { get; set; } 
           /// <summary>
           ///  父ID
           /// </summary>
           public string PID { get; set; }
       }
    }
}
